package com.codedef.library.service;

import com.codedef.library.util.Reserver;
import org.springframework.stereotype.Service;

@Service
public class QueryService {

    public String querySeatSection(int startSeat, int endSeat, String date, String startTime, String endTime,
                                   int peopleNum) {
        // date --> 2020-10-02
        Reserver reserver = new Reserver();
        boolean isLogin = reserver.login("16111205178", "16111205178");
        System.out.println("是否登陆成功：" + isLogin);
        // 查询组数
        int groupNum = (endSeat - startSeat) / peopleNum;

        StringBuilder seatBuilder = new StringBuilder();
        // 查询groupNum组
        for (int i=0; i<groupNum; i++) {
            boolean flag = true;
            StringBuilder builder = new StringBuilder();
            for (int j=0; j<peopleNum; j++) {
                int sid = startSeat + i * peopleNum + j;
                boolean b = reserver.querySeat(String.valueOf(sid), date, startTime, endTime);
                if (!b) {
                    flag = false;
                    break;
                }
                builder.append(sid).append(',');
            }
            if (flag) {
                builder.deleteCharAt(builder.length() - 1);
                seatBuilder.append(builder.toString()).append(';');
            }
        }
        seatBuilder.deleteCharAt(seatBuilder.length() - 1);

        return seatBuilder.toString();
    }

}
